<template>
  <div :class="prefixCls">
    <template v-for="item in colorList || []" :key="item.id">
      <a-tooltip>
        <template #title>{{ item.name }}</template>
        <span
          @click="handleClick(item.color)"
          :class="[
            `${prefixCls}__item`,
            {
              [`${prefixCls}__item--active`]: def === item.color,
            },
          ]"
          :style="{ background: item.color }"
        >
          <CheckOutlined />
        </span>
      </a-tooltip>
    </template>
  </div>
</template>
<script lang="ts">
  import { defineComponent, PropType } from 'vue';
  import { CheckOutlined } from '@ant-design/icons-vue';
  import { ColorInfo } from '../calendar.d';
  import { useDesign } from '/@/hooks/web/useDesign';

  export default defineComponent({
    name: 'PlanColorPicker',
    components: { CheckOutlined },
    props: {
      colorList: {
        type: Array as PropType<ColorInfo[]>,
        defualt: [],
      },
      def: {
        type: String,
        defaut: '',
      },
      disabled: {
        type: Boolean,
        default: false,
      },
    },
    emits: ['change'],
    setup(props, { emit }) {
      const { prefixCls } = useDesign('setting-theme-picker');

      function handleClick(color: string) {
        if (props.disabled) {
          return;
        }
        console.log('planColor is ' + color, props.colorList);
        emit('change', color);
      }

      return {
        prefixCls,
        handleClick,
      };
    },
  });
</script>
<style lang="less">
  @prefix-cls: ~'@{namespace}-setting-theme-picker';

  .@{prefix-cls} {
    display: flex;
    flex-wrap: wrap;
    margin: 0px 0;
    justify-content: space-around;

    &__item {
      width: 20px;
      height: 20px;
      cursor: pointer;
      border: 1px solid #ddd;
      border-radius: 2px;

      svg {
        display: none;
      }

      &--active {
        border: 1px solid lighten(@primary-color, 10%);

        svg {
          display: inline-block;
          margin: 0 0 3px 3px;
          font-size: 12px;
          fill: @white !important;
        }
      }
    }
  }
</style>
